﻿<div class="ld-tabs">
    <ul>
        <li class="k-state-active">单据明细列表</li>
    </ul>
    <div>
        <div class="k-block divToolbar">
            <div style="display: inline-block;">
                <input id="selHouse" />
            </div>
            <input type="text" placeholder="请输入单据号" id="txtKey" class="k-textbox" />
            
            <div style="display: inline-block;">
                <select id="ddlMethod">
                    <option value="">全部单据</option>
                    <option value="11">入库单</option>
                    <option value="12">出库单</option>
                    <option value="13">盘存调拨</option>
                </select>
            </div>
            <br />
            <br />
            <div style="display: inline-block;">
                <input id="txtProduct" data-value="0" />
            </div>
            <div style="display: inline-block;">
                <input id="txtMaterial" data-value="0" />
            </div>
            <div style="display: inline-block;">
                <input id="txtProcess" data-value="0" />
            </div>
            <div style="display: inline-block;">
                <input id="txtSize" data-value="0" />
            </div>
            <br />
            <br />
            <div style="display: inline-block;">
                <input id="txtOrderDateBefore" class="date" placeholder="开始时间" />
            </div>
            --
            <div style="display: inline-block;">
                <input id="txtOrderDateAfter" class="date" placeholder="结束时间" />
            </div>
            <button class="k-button" onclick="FilterOrders()"><span class="k-icon k-i-search"></span><span>搜索</span></button>
        </div>
        <div id="grid_orders" style="text-align: center"></div>
    </div>
</div>

<script class="init">
    LocatedMenu("仓库管理", "单据查询");

    $("#ddlMethod").kendoDropDownList();

    $("#selHouse").kendoDropDownList({
        dataTextField: "House",
        dataValueField: "ID",
        dataSource: Whale.dataSource({
            url: "/Products/Warehouse/Gets"
        })
    });

    var allProducts = Whale.Remote.GetEntity({
        url: "/Products/Product/Gets",
        parameters: {
            pageSize: 0,
            productStatus: 1
        }
    });
    var materials = Whale.Remote.GetEntity({
        url: "/Products/Material/Gets"
    });
    var processes = Whale.Remote.GetEntity({
        url: "/Products/Process/Gets"
    });
    var sizes = Whale.Remote.GetEntity({
        url: "/Products/Size/Gets"
    });
    $("#txtProduct").kendoComboBox({
        placeholder: "请选择产品...",
        filter: "contains",
        dataTextField: "Module",
        dataValueField: "ID",
        dataSource: allProducts,
        select: function (e) {
            var item = this.dataItem(e.item.index());
            $("#txtProduct").attr("data-value", item.ID);
        },
        change: function (e) {
            if (!$.isNumeric(this.value())) {
                this.text("");
                $("#txtProduct").attr("data-value", "0");
            }
        }
    });

    $("#txtMaterial").kendoDropDownList({
        optionLabel: {
            MaterialName: "请选择材料...",
            ID: 0
        },
        dataTextField: "MaterialName",
        dataValueField: "ID",
        dataSource: materials
    });

    $("#txtProcess").kendoDropDownList({
        optionLabel: {
            ProcessName: "请选择加工...",
            ID: 0
        },
        dataTextField: "ProcessName",
        dataValueField: "ID",
        dataSource: processes
    });

    $("#txtSize").kendoDropDownList({
        optionLabel: {
            SizeName: "请选择规格...",
            ID: 0
        },
        dataTextField: "SizeName",
        dataValueField: "ID",
        dataSource: sizes
    });

    $(".date").kendoDatePicker({
        culture: "zh-CHS",
        format: "yyyy年MM月dd日",
    });
</script>

<script class="product_search">

</script>

<script class="grid_customer_columns">
    var ordersFields = [{
        title: "单据类别",
        template: "#=GetOrderName(Method)#",
        width: 80
    }, {
        title: "单据号",
        field: "OrderNo",
        template: "#=GetProductOrder(OrderNo)#",
        width: 120
    }, {
        title: "产品型号",
        field: "Module",
        width: 150
    }, {
        title: "材料",
        field: "MaterialName",
        width: 120
    }, {
        title: "加工",
        field:"ProcessName",
        width: 60
    }, {
        title: "规格",
        field: "Size",
        width: 60
    }, {
        title: "数量",
        field: "QuantityAndUnit",
        width: 100,
        attributes: { style: "text-align:right" }
    }, {
        title: "库存量",
        field: "BalanceAndUnit",
        width: 100,
        attributes: { style: "text-align:right" }
    }, {
        title: "日期",
        template: "#=kendo.toString(kendo.parseDate(NoteDate),'yyyy-MM-dd')#",
        width: 100
    }, {
        title: "备注",
        field: "Description",
        width: 200
    }, {
        title: "经办人",
        field: "Operator",
        width: 100
    }, {}];

    function GetProductOrder(orderNo) {
        var html = "<a href=\"javascript:ShowProductOrder('" + orderNo + "')\">" + orderNo + "</a>";
        return html;
    }

    function ShowProductOrder(orderNo) {
        if (wndGeneralEdit != null && typeof wndGeneralEdit != "undefined") {
            wndGeneralEdit.setOptions({ title: "单据详情", width: 800 });
            wndGeneralEdit.refresh({ url: "/Orders/ProductOrder/Order/" + orderNo });
            wndGeneralEdit.open();
        }
    }

    function GetDealOrder(associatedDealOrder) {
        var html = "";
        if (associatedDealOrder != null)
            html += "<a href=\"javascript:ShowDealOrder('" + associatedDealOrder.OrderNo + "')\">" + associatedDealOrder.OrderNo + "</a>";
        return html;
    }

    function ShowDealOrder(orderNo) {
        if (wndGeneralEdit != null && typeof wndGeneralEdit != "undefined") {
            wndGeneralEdit.setOptions({ title: "单据详情", width: 800 });
            wndGeneralEdit.refresh({ url: "/Orders/DealOrder/Order/" + orderNo });
            wndGeneralEdit.open();
        }
    }
</script>

<script class="grid_config">
    $(function () {
        $("#grid_orders").kendoGrid({
            columns: ordersFields,
            dataSource: Whale.dataSource({
                url: "/Orders/ProductOrder/GetViewOrders",
                getParameters: function () {
                    return {
                        productID: $("#txtProduct").attr("data-value"),
                        materialID: $("#txtMaterial").data("kendoDropDownList").value(),
                        processID: $("#txtProcess").data("kendoDropDownList").value(),
                        size: $("#txtSize").data("kendoDropDownList").value()>0?$("#txtSize").data("kendoDropDownList").text():"",
                        orderDateBefore: $("#txtOrderDateBefore").val(),
                        orderDateAfter: $("#txtOrderDateAfter").val(),
                        orderNo: $("#txtKey").val(),
                        orderMethod: $("#ddlMethod").data("kendoDropDownList").value(),
                        houseID: $("#selHouse").data("kendoDropDownList").value()
                    };
                },
                pageSize: 20
            }),
            pageable: {
                messages: {
                    empty: "暂无数据"
                }
            },
            dataBound: function (e) {
                //让表头居中
                $("th.k-header").attr("style", "text-align:center; font-weight:bold;");
            }
        });
    });

    function FilterOrders() {
        $("#grid_orders").data("kendoGrid").dataSource.page(0);
    }
</script>
